package cn.hongwei.definitionregister;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author Great
 * @email 1224028994@qq.com
 */
@Component
public class MyRegister implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        //通过注册bean的定义注册bean
        AbstractBeanDefinition bd=new RootBeanDefinition();
        bd.setBeanClass(PersonDao.class);
        bd.setScope("singleton");
        bd.setLazyInit(false);

        registry.registerBeanDefinition("personDao",bd);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        //这是父接口的方法,上一个案例已经实现过了
    }
}
